package com.ladlee.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.ladlee.properties.DruidProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: dingchang
 * @Date: 2018/12/24 14:35
 * @Description: mybatis-plus的配置
 */
@Configuration
@MapperScan(basePackages={"com.ladlee.system.dao"})
public class MybatisPlusConfig {

    @Autowired
    DruidProperties DruidProperties;

    /**
     * 将配置文件里面的属性注入到数据源配置里面
     * @return
     */
    private DruidDataSource druidDataSourceConfig() {
        DruidDataSource druidDataSource = new DruidDataSource();
        DruidProperties.config(druidDataSource);
        return druidDataSource;
    }

    /**
     * 在容器中注册driud数据源（单个数据源）
     * @return
     */
    @Bean
    public DruidDataSource druidDataSource() {
        return druidDataSourceConfig();
    }

}
